import { DEFAULT_ICON } from '@/initialization';
import useSystemStore from '@/store/system';
import { joinUrl } from '@/utils/file/format';

/* 默认地址， */
export const staticHost = ref<string>(import.meta.env.VITE_STATIC_URL);

/* 通过完整路径 */
export const getImageByFullPath = (src: string) => {
  const sysStore = useSystemStore();
  return joinUrl(sysStore.$state.developer.resourceHost, src);
};
/**
 * @description: 获取网页图标
 * @param {string} src
 */
export const getFavicon = (src: string) => {
  return `https://www.favicon.vip/get.php?url=${src}`;
};

/**
 * @description:
 * 读取系统图标
 * 采用 {system/}前缀 区分自定义Icon和系统ICON
 * 系统ICON能切换风格
 * 自定义ICON需要完整路径
 * 需要切换风格图标必须以 system/开头
 * @param {string} name
 */
export const getSystemIcon = (name: string) => {
  const prefix = 'system/';
  if (!name?.startsWith(prefix)) {
    return joinUrl(staticHost.value, name);
  }
  return joinUrl(staticHost.value, `${joinUrl(DEFAULT_ICON.value, name.replace(prefix, ''))}`);
};
